# Contributor: Alethea Rose <alethea@alethearose.com>

_realname=npm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.3.0
pkgrel=1
pkgdesc='The package manager for JavaScript (mingw-w64)'
arch=('any')
url='https://www.npmjs.com/'
license=('custom:Artistic')
depends=('winpty' "$MINGW_PACKAGE_PREFIX-nodejs")
makedepends=('tar')
optdepends=("${MINGW_PACKAGE_PREFIX}-python2: for node-gyp")
options=('!emptydirs')
_marked_ver=0.3.6
_marked_man_ver=0.2.0

source=("npm-$pkgver.tar.gz::https://github.com/npm/npm/archive/v$pkgver.tar.gz"
        "npm-marked-man-$_marked_man_ver.tgz::https://registry.npmjs.org/marked-man/-/marked-man-$_marked_man_ver.tgz"
        "npm-marked-$_marked_ver.tgz::https://registry.npmjs.org/marked/-/marked-$_marked_ver.tgz")
noextract=("npm-$pkgver.tar.gz"
           "npm-marked-$_marked_ver.tgz"
           "npm-marked-man-$_marked_man_ver.tgz")

sha256sums=('a4b083e0694ce786777d55f803551635b7c958e773b4ff5990103eab7c6e46a2'
            'ea48226f08675656a9794d44aef458e10d076b5f116be77a04986122b7c1c4c2'
            '46f71f8b9cbb5606b166af554958c67f2de6b3346ebe8c8fcc92470252af00c3')

prepare() {
  cd "${srcdir}"
  tar -xf "npm-${pkgver}.tar.gz"
}

build() {
  cd "${srcdir}"/npm-${pkgver}

  node cli.js install ../npm-marked-${_marked_ver}.tgz
  node cli.js install ../npm-marked-man-${_marked_man_ver}.tgz
  make
}

package() {
  cd "${srcdir}"/npm-${pkgver}

  make NPMOPTS="--prefix=\"${pkgdir}${MINGW_PREFIX}/bin\"" install

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/man"
  cp -r man/* "${pkgdir}${MINGW_PREFIX}/share/man"
}
